﻿using System;

using TempEmployees.DAL;
using TempEmployees.BLL.Database;

namespace TempEmployees.BLL.Validations
{
    public class ValidationMethods
    {
        /// <summary>
        /// Checks that the given assignment dates are valid.
        /// 1. startDate must occur before endDate.
        /// 2. if budget type is Technioni, the given dates should be inside the given semester.
        /// </summary>
        /// <param name="startDate">the start date of the assignment</param>
        /// <param name="endDate">the end date of the assignment</param>
        /// <param name="semesterId">the id of the semester associated with the assignment, must be a valid id</param>
        /// <param name="budgetType">the assignment's budget type</param>
        /// <returns>true if valid, false else</returns>
        public static bool ValidateStartEndDates(DateTime startDate, DateTime endDate, int semesterId, DbConstants.BudgetType budgetType)
        {
            if (startDate.CompareTo(endDate) > 0) return false;
            if (budgetType == DbConstants.BudgetType.Mosadi) return true;
            Semester semester;
            if ((semester = DbQuery.GetSingleRow<Semester>("ID", semesterId)) == null)
            {
                return false;
            }
            if (semester.StartDate.CompareTo(startDate) > 0 || endDate.CompareTo(semester.EndDate) > 0)
                return false;
            return true;
        }
    }
}
